// JavaScript Document
Screen = {
	/*设置背景*/
	setBg:function(){
		$(".bg").height(window.innerHeight);
		if($("#playBox").length !==0){
			$("#playBox").height(window.innerHeight);
		}
		window.addEventListener("orientationchange", function(){
			setTimeout(function(){
					$(".bg").height(window.innerHeight);
					if($("#playBox").length !==0){
						$("#playBox").height(window.innerHeight);
					}
				},200)
			}, false); 
		},
	/*手机浏览器的大小*/
	size:function(){
		return [window.innerWidth,window.innerHeight]
		}
	}
	
	
/*
MyPoker类
	公共属性
	---------------------------------------------------------
	pokeyBox -- 放牌的盒子
	putPokeyBox -- 出牌的盒子
	pokeyButton -- 按钮的盒子
	myMsg -- 消息的按钮
	myPokeyName  -- 名字的盒子
	myPokeyHead -- 头像的盒子
	threePoker -- 三张牌的盒子
	---------------------------------------------------------
	公共方法：
	get ---  得到牌
	put --- 出牌
	_button --- 显示按钮管理 
			1、reday  【准备】
			2、bid 【不叫，1分，2分，3分】
			3、pull 【拉、不拉】
			4、put 【出、不出】
	-----------------------------------------
	私有方法
	_createPokey 创建手牌

*/

/*牌 cardSpades黑桃 cardHearts红桃 cardPlum梅花  cardSquare方片*/
	var pokeyArray = ["cardSpades","cardHearts","cardPlum","cardSquare"];
	var pokeyArrayNum = ["3","4","5","6","7","8","9","10","J","Q","K","A","2"];
	var playerGrade = [["短工",0],["长工",100],["佃户",200],["贫农",400],["渔夫",600],["猎人",1000],["中农",2000],["富农",4000],["掌柜",6000],["商人",10000],["衙役",20000],["小财主",50000],["大财主",100000],["小地主",200000],["大地主",500000],["知县",1000000],["通判",2000000],["知府",5000000],["总督",10000000],["巡抚",20000000],["丞相",50000000],["帝王",100000000]]
	
	function MyPoker(name){
		this.name =name;
		this.noPutNums=0;
		this.pokeyBox = $("#pokeyBox");
		this.putPokeyBox = $("#putPokeyBox");
		this.pokeyButton = $("#myButton");
	}
	
	
	MyPoker.prototype = {
		
		/*进入房间
			绑定牌的事件
			设置工具栏
		*/
		goin:function(){
			toolBar.init();
			toolBar.hideBack();
			this._bindEvent();			
			console.log("你进入房间");
		},
		
		/*得到牌
		 * 得到发牌音乐 videoEffect.get()
		 * 创建手牌 this._createPokey(arr);
		 * 显示展开牌的动画 this._animationShowPoker(arr);
		 * 创建属性 this._proto();
		*/	
		get:function(arr){
				console.log("你发了17张牌："+arr);
				videoEffect.get();
				this._createPokey(arr);
				this._setPokeyMargin();
				this._proto();
				var _t = this;
				setTimeout(function(){
					_t._startSetPost();
					_t._animationShowPoker(arr);
				},0)
			},
		
		/*重连时直接获取牌
		 * 得到发牌音乐 videoEffect.get()
		 * 创建手牌 this._createPokey(arr);
		 * 显示牌【无需动画显示】
		 * */
		reGet:function(arr,isShowBgPokey){
			console.log("你重连时的牌："+arr);
			videoEffect.get();
			this._createPokey(arr);
			this._setPokeyMargin();
			this._proto();
			var _t = this;
			setTimeout(function(){
				if(!isShowBgPokey){
					_t._startSetPost(true);
				}
				_t.pokeyBox.find(".card").css({
					"opacity":100										   
				});
			},0)
			
			
			
			
			
		},
			
		/*把三张牌插入手牌中,并显示插入效果
		 * 创建三张底牌this._createBottomPokey(arr);
		 * 设置牌的间距this._setPokeyMargin();
		 * 设置三张底牌的位置 this._setBottomPokerPost(arr);
		 * 顶部得到三张牌toolBar.getBottomPokey(arr);
		*/
		
		getBottomPoker:function(arr){
			console.log("你发了3张底牌："+arr);
			this._createBottomPokey(arr);
			this._setPokeyMargin();
			this._setBottomPokerPost(arr);
			toolBar.getBottomPokey(arr);
			},
			
			
			
		/*点击出牌按钮
		 * 获取点击时得到的牌 this._getPut();
		 * 判断  如果没有选择牌 
		 * 规则验证
		 * 删除已选择的牌 this._removePut();
		 * 清空按钮this.button().clear();
		 * 设置牌的间距this._setPokeyMargin();
		 * 隐藏我的牌信息 player.hideMsg("my");
		 * 显示出了牌在桌面上 player.put("my",putArr);
		*/
		put:function(isMustPut){
				var putArr = this._getPut();
				console.log("-----请选择牌" + putArr.length + " ----"+putArr);
				/*没有选择牌，就点出牌*/
				if(putArr.length === 0){
					player.msg("my","text-selectPokey");
					return;
					}
					
				/*
				是不是我先出牌
				*/
				
				if(isMustPut){
					var type = Rule.getSType(putArr);
						console.log("我先出--是不是符合出牌规则:"+type);
					if(type == -1){
						player.msg("my","text-noAccord");
						return;
						}
				}else{
					var prevPokey = getPerOutCards();
					console.log("是不是符合出牌规则:"+Rule.canOut(prevPokey,putArr));
					
					if(!Rule.canOut(prevPokey,putArr)){
						player.msg("my","text-noAccord");
						return;
						}	
				}
				
				this._removePut();
				this.button().clear();
				this._setPokeyMargin();
				player.hideMsg("my");
				//player.put("my",putArr);
				gameOnOutCard(putArr);
			
			},
			
			
			
			
		/*按钮管理和进程管理
		*/	
		button:function(){
			var _t = this;
			
			return{
				
				
			
				/*准备*/
				ready:function(){
					//var b = "<input name='' type='button' value='准 备'  class='pokeyButton button-blue ' id='button-ready'/>";
					var buttonArray = ["<input name='' type='button' value='返回大厅'  class='pokeyButton button-blue ' id='button-return'/>",
					                   "<input name='' type='button' value='准 备'  class='pokeyButton button-blue ' id='button-ready'/>"
									  ];
					var b = buttonArray[0]+ buttonArray[1];	
					_t.pokeyButton.html(b);
					$("#button-ready").click(function(){
							gameOnReady();
							videoEffect.ready();
							_t.button().clear();
						});
					
					$("#button-return").click(function(){
						room.goin();
						_t.button().clear();
					});
					
					},
					
					
				/*叫地主*/
				bid:function(n, fun,timeOut){
					var n = n || 0;
					var buttonArray = ["<input name='' num='0' type='button' value='不叫'  class='pokeyButton button-blue ' id='button-no'/>",
									   "<input name='' num='1' type='button' value='1分'  class='pokeyButton button-blue ' id='button-one'/>",
									   "<input name='' num='2' type='button' value='2分'  class='pokeyButton button-blue ' id='button-two'/>",
									   "<input name='' num='3' type='button' value='3分'  class='pokeyButton button-blue ' id='button-three'/>"];
					
					var b="";
					if(n==0){
						b = buttonArray[0]+ buttonArray[1]+ buttonArray[2]+ buttonArray[3];
					}else if(n == 2){
						b = buttonArray[0]+ buttonArray[2]+ buttonArray[3];	
					}else if(n == 3){
						b = buttonArray[0]+ buttonArray[3];	
					}
					_t.pokeyButton.html(b);
					
					
					//console.log(n+"--->"+_t.pokeyButton.html()+":"+b)
					player.countdown("my", fun,timeOut);
					
					/*不叫*/
					$("#button-no").click(function(){
								_t.button().clear();
								var num = $(this).attr("num");
								gameOnGrabLandLord(num);
						});
					
					/*1分*/
					$("#button-one").click(function(){
								_t.button().clear();
								var num = $(this).attr("num");
								gameOnGrabLandLord(num);
								
						});
					
					/*2分*/
					$("#button-two").click(function(){
								_t.button().clear();
								var num = $(this).attr("num");
								gameOnGrabLandLord(num);
								
						});
					
					/*3分*/
					$("#button-three").click(function(){
								_t.button().clear();
								var num = $(this).attr("num");
								gameOnGrabLandLord(num);
						});
					},
					
					
				/*加倍*/
				pull:function(playerId,fun,timeout){
					
					var buttonArray = ["<input name='' type='button' value='加倍'  class='pokeyButton button-blue ' id='button-pull'/>",
									   "<input name='' type='button' value='不加倍'  class='pokeyButton button-blue ' id='button-nopull'/>"];
					
					var b = buttonArray[0]+ buttonArray[1];	
					_t.pokeyButton.html(b);
					player.countdown("my",fun,timeout);
					
					$("#button-pull").click(function(){
								_t.button().clear();
								gameDouble(true,playerId);
						});
					
					$("#button-nopull").click(function(){
								_t.button().clear();
								gameDouble(false,playerId);
						});
					},
					
					
				/*出牌阶段 出 不出 提示
				* isMustPut 是否必出  把“不出”按钮隐藏
				*/
				put:function(isMustPut,fun){
					var isMustPut = isMustPut || false;
					var buttonArray = ["<input name='' type='button' value='不出'  class='pokeyButton button-blue ' id='button-noput'/>",
									   "<input name='' type='button' value='提示'  class='pokeyButton button-blue ' id='button-prompt'/>",
									   "<input name='' type='button' value='重选'  class='pokeyButton button-blue ' id='button-reSelect'/>",
									   "<input name='' type='button' value='出牌'  class='pokeyButton button-blue ' id='button-put'/>"
									  ];
					
					var b = "";
					if(isMustPut){
						b =buttonArray[1]+ buttonArray[2]+ buttonArray[3];
					}else{
						b = buttonArray[0]+ buttonArray[1]+ buttonArray[2]+ buttonArray[3];	
					}
					
					_t.pokeyButton.html(b);
					player.countdown("my",fun);
					
					/*不出*/
					$("#button-noput").click(function(){
							gameOnNotOutCard(); // 不出牌
							 _t.button().clear();
							 player.msg("my","text-noPut");
							 _t.reSelectPokey();
						});
					
					var clickNum = 0;
					var timeStamp = new Date().getTime();
					
					/*提示*/
					$("#button-prompt").click(function(){
							gameOnRequestOutCardSussestion(clickNum,timeStamp);
							clickNum++;
						});
					
					/*重选*/
					$("#button-reSelect").click(function(){
							_t.reSelectPokey();
						});
					
					/*出牌*/
					$("#button-put").click(function(){
							_t.put(isMustPut);
							videoEffect.put();
						});
					},
					
				
				
				/*清空*/
				clear:function(){
					_t.pokeyButton.html("");
					player.hideCountdown();
					}
					
				}
				
				
				
			},
			
			
			/*提示时给出选择牌
			 * 把所有的牌初始化 
			 * 选择要提示的牌
			 * */
			selectPokey:function(arr){
				this.pokeyBox.find(".card").attr("isSelect",0);
				this.pokeyBox.find(".card").css({"top":0});
				for(var i=0; i<arr.length; i++){
					$("#"+arr[i]).attr("isSelect",1);
					$("#"+arr[i]).css({"top":-20});
					}
				},
				
			/*重选
			 * 把所有的牌初始化
			 * */
			reSelectPokey:function(){
				this.pokeyBox.find(".card").attr("isSelect",0);
				this.pokeyBox.find(".card").css({"top":0});
				},
				
				
			/*托管选择一手牌
			 * 选择要出的牌
			 * 删除已选择的牌 this._removePut();
			 * 清空按钮this.button().clear();
			 * 设置牌的间距this._setPokeyMargin();
			 * 显示出了牌在桌面上 player.put("my",arr);
			 * */
			trusteePut:function(arr){
				this.reSelectPokey();
				var _t = this;
				for(var i=0;i<arr.length; i++){
					var y = function(n){
						$("#"+arr[n]).attr("isSelect",1);
						$("#"+arr[n]).css({"top":-20});
					}(i)
				}
				
				this._removePut();
				this.button().clear();
				this._setPokeyMargin();
				player.put("my",arr);
			},
			
			
			
			/************************************私有方法*****************************************/
			
		
		/*创建手牌
		 * 生成DOM节点
		 * 设置透明度
		 * 设置牌的间距this._setPokeyMargin();
		 * 设置三张背景底牌的位置 this._startSetPost();
		 * */
			_createPokey:function(arr){
					var html="";
					console.log("你得到"+arr.length+"张牌,他们是"+arr);
					for(var i=arr.length-1; i>=0; i--){
						var type = pokeyArray[arr[i]%4];
						var num = pokeyArrayNum[Math.floor(arr[i]/4)];
						
						if(parseInt(arr[i]) === 53){
							html+="<span id='"+arr[i]+"' class='card cardBgPng smallKing' style='z-index:"+(100-arr[i])+"' isSelect='0'></span>";
						}else if(parseInt(arr[i]) === 56){
							html+="<span id='"+arr[i]+"' class='card cardBgPng bigKing' style='z-index:"+(100-arr[i])+"' isSelect='0'></span>";
						}else{
							html+="<span id='"+arr[i]+"' class='card cardBgPng "+type+"' style='z-index:"+(100-arr[i])+"' isSelect='0'><span class='cardFont'>"+num+"</span></span>";
						}
						}
					//console.log(html)
					/*插入并设置透明度为0*/
					this.pokeyBox.html(html).find(".card").css({
						"opacity":0										   
					});
					
					
				},
				
				
			/*创建三张底牌*/
			_createBottomPokey:function(arr){
				var _t = this;
				
				for(var i=0; i<arr.length; i++){
					var y = function(n){
						var insertArr = _t._insertPosition(arr[n]);
						
						var type = pokeyArray[arr[i]%4];
						var num = pokeyArrayNum[Math.floor(arr[i]/4)];
						
						if(parseInt(arr[i]) === 53){
							var html="<span id='"+arr[i]+"' class='card  cardBgPng smallKing' style='z-index:"+(100-arr[i])+"' isSelect='0'></span>";
						}else if(parseInt(arr[i]) === 56){
							var html="<span id='"+arr[i]+"' class='card  cardBgPng bigKing' style='z-index:"+(100-arr[i])+"' isSelect='0'></span>";
						}else{
							var html="<span  id='"+arr[i]+"' class='card cardBgPng "+type+"' style='z-index:"+(100-arr[i])+"' isSelect='0' ><span class='cardFont'>"+num+"</span></span>";
							}
						
						if(insertArr[0] === "after"){
							$("#"+insertArr[1]).after(html);
						}else{
							$("#"+insertArr[1]).before(html);
							}
					}(i)
				}
			},
				
			/*开始时设置牌的位置&&底牌背景的位置
			 * 生成背景底牌的DOM节点this._createPokeyBg();
			 * 设置背景底牌的位置
			 * 把所以的牌都定位到底牌的位置【通过动画形式分发到目标位置】*/
			_startSetPost:function(isNoReGet){
				var cards = this.pokeyBox.find(".card");
				/*创建一个背景的底牌 并设置到中央位置*/
				this._createPokeyBg();
				this._pokeyBg.css({
							"top":"40%",
							"left":"45%"
							});
				if(!isNoReGet){
					var ox = this._pokeyBg.offset().left;
					var oy =  this._pokeyBg.offset().top;
					var t = cards.eq(0).offset().top;
					var _t = this;
					/*把所以的牌都定位到中央位置*/
					for(var i=0; i<cards.length; i++){
							var l =  cards.eq(i).offset().left;
							var left = ox-l;
							cards.eq(i).css({
								top:oy-t,
								left:left
							});
						}
				}
				
				},
				
			/*设置手牌的间距 牌少就间距大 牌多就间距小*/
			_setPokeyMargin:function(){
				var cards = this.pokeyBox.find(".card");
				var length = cards.length;
				
				var _t = this;
				setTimeout(function(){
					var oMargin = (Screen.size()[0]-cards.width()-20)/(length-1);
					oMargin = Math.ceil(cards.width() - oMargin);
					oMargin = oMargin>0 ? oMargin : 0;
					_t.pokeyBox.find(".card").css({
							"margin-left":-oMargin/2,	
							"margin-right":-oMargin/2
						})
					},0)
				
				},
				
			/*动画显示手牌*/
			_animationShowPoker:function(){
				var _t = this;
				var cards = this.pokeyBox.find(".card");
				for(var i=0; i<cards.length; i++){
					var y = function(n){
						setTimeout(function(){
							_t.pokeyBox.find(".card").eq(n).animate({
									"opacity":100,
									"top":0,
									"left":0
							},100);
						},50*n);
					}(i)
				}
				
				setTimeout(function(){
						_t._animationShowThreePoker();		
				},50*17)
				},
				
			/*底牌背景*/
			_createPokeyBg:function(){
				var h = "<div  class='threeCard cardBg cardBgPng'></div>";
				$("#playBox").append(h+h+h);
				this._pokeyBg = $(".threeCard");
				},
			
			/*动画展开三张底牌*/	
			_animationShowThreePoker:function(){
				this._pokeyBg.eq(0).animate({
								"left":"35%"
							},50);
				
				this._pokeyBg.eq(2).animate({
								"left":"55%"
							},50);
				},
				
			/* 得到要插入牌的位置*/
			_insertPosition:function(n){
				for(var i = this.pokeyBox.find(".card").length-1; i>=0; i--){
					var num = parseInt(this.pokeyBox.find(".card").eq(i).attr("id"));
					
					/*返回位置*/
					if(n<num){
						return ["after",num];
						}
						
					/*放最后一张*/	
					if(n>parseInt(this.pokeyBox.find(".card").first().attr("id"))){
						return  ["before",parseInt(this.pokeyBox.find(".card").first().attr("id"))];												 
						}
					}
				},
				
			/*设置三张底牌的插入时的初始位置*/
			_setBottomPokerPost:function(arr){
				var _t = this;
				for(var i=0; i<arr.length; i++){
					var y = function(n){
						var obj = $("#"+arr[n]);
						var l = _t._pokeyBg.eq(n).offset().left;
						var t =  _t._pokeyBg.eq(n).offset().top;
						var ol = obj.offset().left;
						var ot = obj.offset().top;
						obj.css({
							top:t-ot,
							left:l-ol
							});
						obj.animate({"top":0,left:0},200);
						}(i);
					}
				},
				
		
				
			/*得到手牌 对手牌进行点击和触摸滑动事件处理*/
			_bindEvent:function(){
		
				var _t = this;
				var isIphone = /i(Phone|P(o|a)d)/.test(navigator.userAgent);
				var card = $("#pokeyBox>.card");
				if(isIphone){
					card.live("touchend",function(e){
						_t._click($(this));
					});
				}else{
					card.live("click",function(e){
						_t._click($(this));
					});
				}
				
				/*body取消默认触摸滑屏事件*/
				$("#pokeyBox").live("touchstart",function(e){
					_t._touchStart(e);
				
				});
				
				$("#pokeyBox").live("touchend",function(e){
					_t._touchEnd(e);
				});
				
				$("#pokeyBox").live("touchmove",function(e){
					e.preventDefault();
					e.stopPropagation();
				});
				
				/*点击头像查看信息*/
				$(".headIcon").live("click",function(){
													 
						if($(this).isChildOf(".left")){
							player.showHead("left");
							}
							
						if($(this).isChildOf(".right")){
							player.showHead("right");
							}
							
						if($(this).isChildOf(".my")){
							player.showHead("my");
							}
				});
				
				},
				
			
			_click:function(t){
				var _t = this;
				if(t.attr("isSelect") != 0){
					_t._dowmAnim(t);
					}else{
					_t._upAnim(t);
				}
			},
				
			_touchStart:function(e){
				
				var _t = this;
				var pokeyBox = this.pokeyBox.find(".card");
				var x = e.touches[0].pageX ;
				var y = e.touches[0].pageY ;
				var boxLeft = parseInt(pokeyBox.offset().left);
				var boxTop = parseInt(pokeyBox.offset().top)-20;
				var boxHeight = parseInt(pokeyBox.height());
				
				this.selectMinNum = this._touchMoveSelectNum(boxLeft,x,y,boxTop,boxHeight);
					
			},	
				
				
			/*触摸结束时*/	
			_touchEnd:function(e){
				var _t = this;
				var pokeyBox = this.pokeyBox.find(".card");
				var x = e.changedTouches[0].pageX ;
				var y = e.changedTouches[0].pageY;
				var boxLeft = parseInt(pokeyBox.offset().left);
				var boxTop = parseInt(pokeyBox.offset().top)-20;
				var boxHeight = parseInt(pokeyBox.height());
				this.selectMaxNum = this._touchMoveSelectNum(boxLeft,x,y,boxTop,boxHeight);
				var isIphone = /i(Phone|P(o|a)d)/.test(navigator.userAgent);
				if(_t.selectMinNum>_t.selectMaxNum){
					if(isIphone){
						var minNum = _t.selectMaxNum;
						var maxNum = _t.selectMinNum-1;
					}else{
						var minNum = _t.selectMaxNum;
						var maxNum = _t.selectMinNum;
					}
					
				}else if(_t.selectMinNum<_t.selectMaxNum){
					if(isIphone){
						var minNum = _t.selectMinNum+1;
						var maxNum = _t.selectMaxNum;
					}else{
						var minNum = _t.selectMinNum;
						var maxNum = _t.selectMaxNum;
					}
				}else{
					return ;
				}
				//$(".baseScore").append("dowm-"+minNum+":"+maxNum);
				for(var i=minNum; i<=maxNum; i++){
					
					var y = function(n){
							var scard =   _t.pokeyBox.find(".card").eq(n);
							if( scard.attr("isSelect") != 0){
								_t._dowmAnim(scard);
							}else{
								_t._upAnim(scard);
							};
						}(i)
					}
				
					_t.selectMinNum = null;
					_t.selectMaxNum = null;
			
				
				},
				
				/*
				获取牌的属性 私有属性
				_firstPokey 第一张牌
				_pokeyWidth 牌的宽度
				_pokeyRight 牌的margin-right
				_pokeyDistance 牌的距离
				
				*/
				_proto:function(){
					this._firstPokey = this.pokeyBox.find(".card").eq(0);
					this._touchMoveArr = [];
					this.selectMinNum=null,this.selectMaxNum=null;
					
					},
					
					
					
				
				/*
				向上升起 并设置已选中
				参数N  -- 第N张牌
				*/
				_upAnim:function( t ){
					//$(".baseScore").append("up-");
					t.css({"top":-20});
					t.attr("isSelect",1);
					
					},
					
				/*
				下降 并设置未选中
				参数N  -- 第N张牌
				*/
				_dowmAnim:function(t){
					//$(".baseScore").append("dowm-");
					t.css({"top":0});
					t.attr("isSelect",0);
					
					},
					
					
				
				//判断触摸滑动时 是否选中了牌  如果选中了  就返回TRUE 
				_touchMoveSelectNum:function(l,x,y,t,h){
					
					
					if(y<t || y>(t+h+20)){
						return ;
					}
					
					if(x-l<0){
						return 0;
					}	
					var pokeyBox = this.pokeyBox.find(".card");
					var pokeyWidth = pokeyBox.width();
					var pokeyRight = Math.abs(parseInt(pokeyBox.css("margin-right")));
					var pokeyLeft = Math.abs(parseInt(pokeyBox.css("margin-left")));
					var pokeyDistance = pokeyWidth-pokeyRight-pokeyLeft;
					return Math.floor((x - l)/pokeyDistance);
					},
					
					
				//得到要出的牌
				_getPut:function(){
					var length = this.pokeyBox.find(".card").length;
					var arr = [];
					for(var i=0; i<length; i++){
						var n =  this.pokeyBox.find(".card").eq(i).attr("isSelect");
						if(n === "1"){
							arr.unshift(this.pokeyBox.find(".card").eq(i).attr("id"));
							}
						}
					return arr;
					},
					
				/*删除出掉的牌*/
				_removePut:function(){
					var length = this.pokeyBox.find(".card").length;
					for(var i=0; i<length; i++){
						var n =  this.pokeyBox.find(".card").eq(i).attr("isSelect");
						if(n === "1"){
							this.pokeyBox.find(".card").eq(i).remove();
							i--;
							}
						}
					}
					
		}
		
		

/*三个人都公用的方法
1、倒计时  {显示设置 countdown(obj,n), 隐藏 hideCountdown}
2、谈话	 {显示设置 talk(obj,text), 隐藏 hideTalk}
3、信息设置 
   [setInfo().head(obj,isLandlord)头像，
	setInfo().multiple(obj,num)倍数，
	setInfo().name(obj,name) 姓名，
	setInfo().dou(obj,num) 乐豆，
	setInfo().pokeyNum(obj,num) 牌数]
   
   隐藏信息
   hideInfo()
   显示信息
   showInfo()
   
   
4、设置基分{
	setBaseScore(num)显示设置
	hideBaseScore()隐藏
	}
	
5、出牌 put{
		obj 对象
		arr 牌的数组
	}
	
6、显示头像 showHead
7、游戏玩家进入 goin{ obj}
8、提示信息 msg(obj,text) hideMsg();
9、准备 ready(obj)

*/
var player = {
			
			/*游戏玩家进入
			 * 创建头像信息this._createInfo(obj,info);
			 * 设置名字this.setInfo().name(obj,name);
			 * 设置豆this.setInfo().dou(obj,dou);
			 * */
			goin:function(obj,info){
				var name = info.name;
				var dou = info.dou;
				this._createInfo(obj,info);
				this.setInfo().name(obj,name);
				this.setInfo().dou(obj,dou);
				
				},
				
			/*准备
			 * 显示准备信息this.okMsg(obj);*/	
			ready:function(obj){
				this.okMsg(obj);
				},
			
			/*要出的牌
			 * 创建要出牌 this._createPutPokey(arr,box);
			 * 判断 如果是自己 牌居中
			*/
			put:function(obj,arr){
				var box = $("."+obj+" .putpokeyBox");
				this._createPutPokey(arr,box);
				pokeyEffect.anmi(arr);
				if(obj === "my"){
					box.css("margin-left",-box.width()/2)
					}
				},
			
			/*清空手牌*/
			clearPut:function(obj){
				var box = $("."+obj+" .putpokeyBox");
				box.html("");
				},
			
			/*倒计时 
			 * fun 是倒计时结束之后的回调函数
			 * 生成DOM节点
			 * 开始倒计时this._waitCountdown(fun,n);
			*/	
			
			countdown:function(obj,fun,n){
				var n = n || 30;
				if($(".wait")){
					$(".wait").remove();
					}
				clearTimeout(this.waitTimer);
				var html = "<div class='wait cardBgPng "+obj+"Wait'>"+n+"</div>";
				$("#playBox").append(html);
				this._waitCountdown(fun,n);
				},
				
				
			/*隐藏倒计时*/
			hideCountdown:function(){
				if($(".wait")){
					$(".wait").remove();
					}
				if(this.waitTimer){
					clearTimeout(this.waitTimer);
				}
				},
				
			/*谈话信息
			 * 生成DOM节点
			 * 在5秒后删除*/	
			talk:function(obj,text){
				clearTimeout(this._talkTimer);
				if($(".talk")){
					$(".talk").remove();
					}
				var html = "<div class='talk "+obj+"Talk'>"+text+"</div>";
				$("#playBox").append(html);
				
				this._talkTimer = setTimeout(function(){
					$(".talk").remove();				
					},5000);
				},
				
			/*隐藏所有谈话*/	
			hideTalk:function(){
				if($(".talk")){
					$(".talk").remove();
					}
				},
				
			/*设置信息*/	
			setInfo:function(){
				return {
					/*设置头像
					obj 对象
					isLandlord 是否是地主
					*/
					head:function(obj,isLandlord){
						var headIcon = $("."+obj+" .headIcon");
						if(isLandlord){
							headIcon.addClass("landlord");
							}else{
							headIcon.removeClass("landlord");
							}
						},
					
					/*设置倍数
					obj 对象
					num 倍数
					*/
					multiple:function(obj,num){
						var headIcon = $("."+obj+" .pokeyMultiple");
						headIcon.show().html("x"+num);
						},
						
						
					/*设置姓名
					obj 对象
					name 姓名
					*/
					name:function(obj,name){
						var pokeyName = $("."+obj+" .pokeyName");
						pokeyName.html(name);
						},
						
					/*设置豆数
					obj 对象
					num 豆数
					*/
					dou:function(obj,num){
						var pokeyDou = $("."+obj+" .pokeyDou");
						pokeyDou.html(num);
						},
						
					/*设置牌数
					obj 对象
					num 豆数
					*/
					pokeyNum:function(obj,num){
						var pokeyNum = $("."+obj+" .pokeyNum .pokeyNum-num");
						pokeyNum.html(num);
						}
						
					}
				},
				
			/*获取信息*/
			getInfo:function(){
				return {
					name:function(obj){
						var pokeyName = $("."+obj+" .pokeyName");
						return pokeyName.html();
						},
					
					dou:function(obj){
						var pokeyDou = $("."+obj+" .pokeyDou");
						return pokeyDou.html();
						}
					}
				},
				
			/*隐藏信息*/
			hideInfo:function(){
					return {
						/*整个头像*/
						all:function(obj){
							$("."+obj).hide();
						},
						
						/*倍数*/
						multiple:function(obj){
							var pokeyMultiple = $("."+obj+" .pokeyMultiple");
							pokeyMultiple.hide();
							}
						}
						
					},
				
				
			/*显示信息*/	
			showInfo:function(obj){
				$("."+obj).show();
				},
			
			/*设置显示基分*/
			setBaseScore:function(num){
				$(".baseScore").show().html("基分："+num);
				},
				
			/*隐藏基分*/
			hideBaseScore:function(num){
				$(".baseScore").hide();
				},
				
			/*设置炸弹数*/
			setBobNums:function(num){
				$(".bobNums").show().html("炸弹："+num);
				},
				
			/*得到炸弹数*/
			getBobNums:function(){
				return parseInt($(".bobNums").html().slice(3))||0;
			},
					
			/*隐藏炸弹数*/
			hideBobNums:function(){
				$(".bobNums").hide();
				},	
				
			/*显示头像*/
			showHead:function(obj){
				
				var name = this.getInfo().name(obj);
				var dou = this.getInfo().dou(obj);
				var grade = msgBox._getGrade(dou);
		
				if($(".headDiv")){
					$(".headDiv").remove();
					}
					
				var html = "<div class='headDiv toolSetBg "+obj+"HeadDiv'>\
								<ul>\
									<li >昵称："+name+"</li>\
									<li >乐豆："+dou+"</li>\
									<li >等级："+grade+"</li>\
								</ul>\
							</div>";
							
				$("#playBox").append(html);
				
				$(document).click(function(){
					if(!$(event.target).isChildOf(".headDiv") && !$(event.target).isChildAndSelfOf(".headIcon")){
							$(".headDiv").hide();
						}			   
					})
					
				},
				
				
				/*显示弹出信息
				* 1准备 text-ready
				* 2加倍  text-double
				* 3不加倍 text-noDouble
				* 4不出 text-noPut
				* 5我又掉线了 text-downline
				* 6没有大过的牌型 text-noBig
				* 7 出牌不符合规则  text-noAccord
				* 8无人抢地主，重新发牌 text-noGrab
			* */
				msg:function(obj,text){
					if($("."+obj+"Msg").length === 1){
						$("."+obj+"Msg").remove();	
						}
					
					var html = "<div class='msg "+obj+"Msg'><span class='png "+text+"'></span></div>";
					$("#playBox").append(html);
					},
					
				/*隐藏弹出信息*/	
				hideMsg:function(obj){
					$("."+obj+"Msg").remove();
				},
				
				
				/*显示OK准备信息*/
				okMsg:function(obj){
					var html = "<div class='okMsg "+obj+"OkMsg'><span class='png text-ready'></span></div>";
					$("#playBox").append(html);
					},
					
				hideOkMsg:function(){
					$(".okMsg").remove();
					},
					
					
				/*显示托管*/
				showTrusteeship:function(obj){
					if(obj === "my"){
						this._myTrusteeship();
						
					}else{
						this.msg(obj,"托管");
					}
					},
					
				hideTrusteeship:function(obj){
					if(obj === "my"){
						this._hideMyTrusteeship();
					}else{
						this.hideMsg(obj);
					}
					},
					
					
				/*动画显示加分和减分*/
				showAnimDou:function(obj){
					var rD = obj.rightWinChipsCount;
					var lD = obj.leftWinChipsCount;
					
					var html = "<div class='animDou leftAnimDou'>"+lD+"</div>" +
							"<div class='animDou rightAnimDou'>"+rD+"</div>";
					$("#playBox").append(html);
					
					$(".animDou").animate({
						"top":"25%"
					},1500);
				},
				
				clearAnimDou:function(){
					$(".animDou").remove();
				},
					
				
			
				
				
				
	/******************************私有方法****************************************/
				
			/*开始倒计时*/	
			_waitCountdown:function(fun,n){
				var _t = this;
				var countDownNum = n;
				timer();
				function timer(){
					_t.waitTimer = setTimeout(function(){
						if(countDownNum>1){
							clearTimeout(_t.waitTimer);
							countDownNum--;
							$(".wait").html(countDownNum);
							if(countDownNum<6){
								$(".wait").css({"color":"#ff0000"});
							}
							if(countDownNum<4){
								/*倒计时催促*/
								videoEffect.countDown();
							}
							timer();
							
						}else{
							clearTimeout(_t.waitTimer);
							$("#myButton").html("");
							_t.hideCountdown();
							if(fun){
								fun()
							}
							
						}			
					},1000);
				}
				},
				
				
			_createPutPokey:function(arr,box){
				var html="";
				for(var i=arr.length-1; i>=0; i--){
						var type = pokeyArray[arr[i]%4];
						var num = pokeyArrayNum[Math.floor(arr[i]/4)];
						
						if(parseInt(arr[i]) === 53){
							html+="<span  class='card card-amid cardBgPng smallKing' style='z-index:"+(100-arr[i])+"'  isSelect='0'></span>";
						}else if(parseInt(arr[i]) === 56){
							html+="<span  class='card card-amid cardBgPng bigKing' style='z-index:"+(100-arr[i])+"'  isSelect='0'></span>";
						}else{
							html+="<span  class='card-amid card cardBgPng "+type+"' style='z-index:"+(100-arr[i])+"' ><span class='cardFont'>"+num+"</span></span>";
						}
						}
				box.html(html);
				},
			
			
			/*创建个人信息*/
			_createInfo:function(obj,info){
				//如果该信息存在 就删除
				if($("."+obj).length!==0){
					$("."+obj).remove();
				}
				if(obj === "left" || obj === "my" ){
					var h = "<div  class='headIcon cardBgPng'></div><div  class='pokeyMultiple'></div>"
				}else if(obj === "right"){
					var h = "<div  class='pokeyMultiple'></div><div  class='headIcon cardBgPng'></div>"	
				}
				
				var html = "<div class='"+obj+"'>\
								<div class='info'>\
									"+h+"\
									<div  class='pokeyName' ></div>\
									<div  class='pokeyDou' ></div>\
									<div  class='pokeyNum' ><span class='pokeyNum-bg cardBgPng'></span><span class='pokeyNum-num'></span></div>\
								</div>\
								<div class='putpokeyBox'></div>\
							</div>";
							
				$("#playBox").append(html);
				
				if(obj === "my"){
					$("."+obj+" .pokeyNum").remove();
					}
				
				},
				
				
			/*自己托管*/
			_myTrusteeship:function(){
				var html = "<div class='toolTrusteeshipDiv'>"+
						"<div class='toolTrusteeshipDiv-bg'></div>"+
						"<input name=''  type='button' value='取消托管'>"+
					"</div>";
					
				var toolTrusteeshipDiv = $(".toolTrusteeshipDiv");
				var button = $(".toolTrusteeshipDiv input");
				
				if(toolTrusteeshipDiv.length === 0){
						$("#playBox").append(html);
						toolTrusteeshipDiv = $(".toolTrusteeshipDiv");
						button = $(".toolTrusteeshipDiv input");
						requestManaged();
					}else{
						toolTrusteeshipDiv.show();
						requestManaged();	
					}	
						
				_t = this;	
				button.click(function(){
					_t.	_hideMyTrusteeship();			  
				})
				
				},
				
			_hideMyTrusteeship:function(){
				my.noPutNums=0;
				$(".toolTrusteeshipDiv").hide();
				requestUnmanaged();
				}
	}	
	
	
	
	
	
	
	
	

	
	
	




	
	/*弹出信息*/
	var msgBox={
			/*财富排行榜*/
			richList:function(){
				this._addRichListData();
				
			},	
			
			/*个人中心*/
			myInfo:function(){
				var url = getServiceURL() + "/popup/user?userId="+getMyUserId();
				var _t = this;
				Game.ajax({
					  url: url,
					  success: function(data){
						  	var data = JSON.parse(data);
						  	var sex = data.sex;
						  	var nickName = data.nickName;
						  	var userId = data.userId;
						  	var userName = data.userName;
						  	var userDou = data.beanfun;
						  	
						  	var html = "<div style='margin:5px 10px;line-height:30px'>" +
						  			"ID:"+userId+"<br>" +
						  			"用户名："+userName+"<br>" +
						  			"昵称：<input class='input' type='text' id='input' value="+nickName+" /><br>"+
						  			"乐豆："+userDou+"<br>" +
						  			"等级："+_t._getGrade(1000)+"<a href='#' id='chargeCode' style='color:#d1dd58; margin-left:20px;'><span class='codePng png'></span>充值</a><br>" +
						  			"<div style='text-align:center'><input  name='' type='button' value='确定修改'  class='pokeyButton button-yellow' id='ok'/></div></div>";
						  	
						  	$("body").showBox({
								id:"myInfo",
								titleClass:"myInfoText",
								html:html
							
							});
						  	
						  //解决端上诡异的BUG  按钮名字不错
						  	setTimeout(function(){
						  		$("#ok").val("确定修改");
						  	},0);
						  	
						  	$("#ok").click(function(){
						  		Game.ajax({
									  url: "user/editNickName",
									  data:{"nickName":encodeURIComponent($("#input").val())},
									  dataType:"json",
									  success: function(data){
										  if(data.flag==1111){
											  $("#user-nickname").html($("#input").val());
										  }
										  $().alert({"content":data.msgs.join("<br/>")});
									  }
						  		})
						  		
						  	});
						  	
						  	$("#chargeCode").click(function(){
						  		$("#myInfo").hide();
						  		_t.chargeMall();
						  	})
					  }
					});
			},
			
			
			
			/*房间信息*/
			room:function(id){
				var url = getServiceURL() + "/room/show?roomId="+id,
					_t = this,
					G=Game;
				G.ajax({
					  url: url,
					  dataType:"json",
					  success: function(data){
						 	var _room=data.data;
						  	var html= "<div class='roomInfo'>";
						  	//if(data.title)html+=data.title+"<br/>";
						  	switch(_room.type){
						  	case 2:
						  		var stype=_room.signUpType,
						  			sfull=stype>=_room.playerTop?"(满额)":"",
						  			sfee=(stype==3||stype==1)?"已报名":_room.feeEnterFee+"乐豆";
						  		html+="<div><span class='roomInfoLists'>报名费用:<span class='red'>"+sfee+"</span></span><span class='roomInfoLists'>报名人数:<span class='red'>"+_room.signUpNumber+"/"+_room.playerTop+sfull+"</span></span></div>";
						  		html+="<div><span class='roomInfoLists'>开赛人数:<span class='red'>"+_room.playerBottom+"~"+_room.playerTop+"</span>人</span><span  class='roomInfoLists'>比赛局数:<span class='red'>"+_room.partTop+"</span>局</span></div>";
						  		html+=_room.ruleDesc;
						  		if(_room.isOpen){
						  			html+="<div class='roomInfoCountDown'>房间关闭倒计时：<span id='countdown'></span></div>";
						  		}else{
						  			html+="<div class='roomInfoCountDown'>开赛倒计时：<span id='countdown'></span></div>";
						  		}
						  		
						  		//开赛倒计时--start
						  		var diff=_room.diffNextGame,
						  			incream=1,
						  			cdownPid=parseInt($("body").data("_cdownPid"));
						  		function dao(){
						  			
						  			//$("#countdown").html(Math.floor((diff-incream)/60)+":"+(diff-incream)%60);
						  			cdownPid=setTimeout(function(){
						  				if(incream<diff){
						  					var minute = Math.floor((diff-incream)/60);
						  					var second = (diff-incream)%60;
						  					if(second<10){
						  						second = "0"+second;
						  					}
						  					$("#countdown").html(minute+":"+second);
						  					dao();
						  				}else{
						  					clearTimeout(cdownPid);
						  					$("#countdown").html("");
						  					room.createRoom();
						  				}
						  				incream++;
						  			},1000);
						  			$("body").data("_cdownPid",cdownPid);
						  		}
						  		clearTimeout(cdownPid);
						  		dao();
						  		html+="<div style='text-align:center'>";
						  	//开赛倒计时--end
						  	 	if(data.flag==1111){
						  	 		var val="";
						  	 		switch(_room.signUpType){
						  	 		case 1://已报名—已开赛
						  	 			html+="<input  name='' type='button' value='开始游戏'  class='pokeyButton button-yellow' id='beginGame'/>";
						  	 			break;
						  	 		case 2://未报名—已开赛
						  	 			html+="<input  name='' type='button' value='已经开赛,不能再报名哦'  class='pokeyButton button-gay' disabled='disabled'/>";
						  	 			break;
						  	 		case 3://已报名—未开赛
						  	 			html+="<input  name='' type='button' value='即将开赛'  class='pokeyButton button-gay' disabled='disabled'/>";
						  	 			break;
						  	 		case 4://报名已满员
						  	 			html+="<input  name='' type='button' value='报名已满额'  class='pokeyButton button-gay' disabled='disabled'/>";
						  	 			break;
						  	 		case 5://报名
						  	 			html+="<input  name='' type='button' value='报名'  class='pokeyButton button-yellow' id='signUpRoom'/>";
						  	 			break;
						  	 		}
							  		//html+="<input style='margin: 0px auto;display:block;' name='' type='button' value='开始游戏'  class='pokeyButton button-yellow' id='beginGame'/>";
							  	}
						  		break;
						  	default:
						  		//html+=data.msgs.join("<br/>")+"<br/>";
						  		//乐豆不足
						  		if(_room.isWarnBean==2){
						  			var beanTitle = "<span style='color:red'>乐豆不足</span><input  name='' type='button' value='去商城充值'  class='pokeyButton button-yellow' id='recharge'/>";
						  		}else if(_room.isWarnBean==3){
						  			var beanTitle = "<span style='color:red'>您的乐豆财富已超出本房间限制，请选择合适的房间</span><br/>";
							  	}else{
							  		var beanTitle = "";
							  	}
							  	
						  		html+=_room.ruleDesc;
						  		html+="<div style='text-align:center'>";
							  	if(data.flag==1111){
							  		html+="<input  name='' type='button' value='开始游戏'  class='pokeyButton button-yellow' id='beginGame'/>";
							  	}else{
							  		html+=beanTitle;
							  	}
						  	}

						  	html+="</div></div>";
						  	$("body").showBox({
								id:"roomBox",
								titleClass:"roomText",
								html:html
							
							});
						  	//解决端上诡异的BUG  按钮名字不错
						  	setTimeout(function(){
						  		$("#beginGame").val("开始游戏");
						  	},0);
						  	$("#recharge").click(function(){
						  		msgBox.chargeMall();
						  	});
						  	$("#beginGame").click(function(){
						  		G.ajax({
						  			url: getServiceURL() + "/room/enter?roomId="+id,
						  			dataType:"json",
						  			success:function(data1){
						  				if(data1.flag==1111){
						  					enterRoom(id);
						  				}else{
						  					$().alert({
						  						"content" : data1.msgs.join("<br/>")
						  					});
						  				}
						  				room.createRoom();
						  			}
						  		});
						  		$("#roomBox").remove();
						  	});
						  	$("#signUpRoom").click(function(){
						  		Room.signUp(id);
						  		$("#roomBox").remove();
						  		room.createRoom();
						  	});						  	
					  }
					});
			},
			
			
			/*商城*/
			chargeMall:function(){
				
				var hrf = "store/goods";
				var html="";
				$.getJSON(hrf,function(data) {
					if(data!=undefined){
						var dynaHTML = [];
						dynaHTML.push("<ul class='chargeMallLists'>");
						$.each(data,function(i, goods) {
							var buyHref = "store/buy/"+goods.id;
							var li = "<li>"+
										"<span  class='chargeMallListsImg cardBgPng code-"+(Math.floor(i/2)+1)+"'></span>" +
										"<span  class='chargeMallListsText'>"+goods.name+"<br>价格："+goods.price*100+"e币</span>"+
										"<a class='chargeMallListsHref' href="+buyHref+">购买</a>"+
									"</li>";
							dynaHTML.push(li);
						});
						dynaHTML.push("</ul>");
						html = dynaHTML.join("");
						
						$("body").showBox({
							id:"chargeMall",
							titleClass:"chargeMallText",
							html:html
						});
					}
				});
				
				
			},
			
			
		/*送豆豆*/
			sendDou:function(continLoginCount,userId){
				var text = "你已经连续登录"+ continLoginCount +"天";
				var html = "<div class='sendDouHead'>"+text+"</div>" +
						"<ul class='sendDouLists'>" +
						"<li><span class='sendDouListsBg'><span class='icon cardBgPng code-4'><span class='sendDouListsDou'>200</span></span></span>1天</li>" +
						"<li><span class='sendDouListsBg'><span class='icon cardBgPng code-4'><span class='sendDouListsDou'>400</span></span></span>2天</li>" +
						"<li><span class='sendDouListsBg'><span class='icon cardBgPng code-4'><span class='sendDouListsDou'>600</span></span></span>3天</li>" +
						"<li><span class='sendDouListsBg'><span class='icon cardBgPng code-4'><span class='sendDouListsDou'>800</span></span></span>4天</li>" +
						"<li><span class='sendDouListsBg'><span class='icon cardBgPng code-4'><span class='sendDouListsDou'>1000</span></span></span>5天</li>" +
						"</ul>"
				$("body").showBox({
					id:"sendDou",
					titleClass:"sendDouText",
					html:html
				});
				
				$("#sendDou .showBox-content-box").css({
					height:120
				});
				
				if($(".showBox-content-bottom").length === 0){
					$("#sendDou .showBox-content-box").after("<div class='showBox-content-bottom'><div style='color:#fff; margin:5px 0px 5px 0px; font-size:12px; line-height:20px;'>" +
							"奖励说明：<br> 前5天登录可获得不同价值的乐豆，5天后持续登录可获得更丰厚乐豆奖励。</div>" +
							"<input style='margin: 0px auto;display:block;' name='' type='button' value='领 取'  class='pokeyButton button-yellow' id='ok'/></div>");
				}
				
				var list = $("#sendDou .sendDouListsBg");
				list.slice(0,continLoginCount).addClass("sendDouListsBg-on");
				
				//解决端上诡异的BUG  按钮名字不错
			  	setTimeout(function(){
			  		$("#ok").val("领 取");
			  	},0);
				
				$("#ok").click(function(){
					// 领取乐豆
					gameReceiveFreeBeanFun(continLoginCount, userId);

				});
				
			},
			
		/*比赛房的信息  查看当前人员的比赛情况*/	
		gameRankInfo:function(){
			var url = getServiceURL() + "/popup/rank?roomId="+getRoomId()+"&userId="+getMyUserId();
			var _t = this;
			/*
			var data = {"maxMatchCount":10,
					"myChipCount":1000,
					"rankList":[
					            {"rankLevel":1,"nickName":"wolfers","chipCount":1000,"matchCount":0,"rankLevelChange":0},
					            {"rankLevel":1,"nickName":"wolfers","chipCount":1000,"matchCount":0,"rankLevelChange":0},
					            {"rankLevel":1,"nickName":"wolfers","chipCount":1000,"matchCount":0,"rankLevelChange":0},
					            {"rankLevel":1,"nickName":"wolfers","chipCount":1000,"matchCount":0,"rankLevelChange":0},
					            {"rankLevel":1,"nickName":"wolfers","chipCount":1000,"matchCount":0,"rankLevelChange":0},
					            {"rankLevel":1,"nickName":"wolfers","chipCount":1000,"matchCount":0,"rankLevelChange":0}
					            ],
					"signUpUserCount":6,
					"myRank":1,
					"myMatchCount":0};
			*/
			
			
			
			
			Game.ajax({
				  url: url,
				  dataType:"json",
				  success: function(data){
					  console.log("得到的数据："+data);
					  $("body").showBox({
							id:"gameRankist",
							titleClass:"gameRankText",
							html:_t._createGameRankInfo(data)
							//headHtml:"我的财富："+json.b+"乐豆<br>排名："+json.r
						});
				  }
				});
			
		},

		/**私有方法***/

		_addRichListData:function(){
			
			var url = getServiceURL() + "/popup/billboardList?userId="+getMyUserId();
			var _t = this;
			Game.ajax({
				  url: url,
				  success: function(data){
					  	createData(JSON.parse(data));
					  	_t._eventRichListData(JSON.parse(data));
				  }
				});
			
			
			function createData(json){
				$("body").showBox({
					id:"richList",
					titleClass:"",
					html:_t._createRichData(json)
					//headHtml:"我的财富："+json.b+"乐豆<br>排名："+json.r
				});
				
				_t._showBox = $(".showBox-content-box");
				//加载排行
				$("#richList").append("<div style='width:100%;position: absolute;z-index: 3;color: #fff;bottom: 0px;text-align: center;'>" +
						"我的财富："+json.b+"乐豆  " +
						"<span style='margin-left:50px'> 排名："+json.r+"</span>" +
				"</div>");
				
				//加载排行
				$("#richList").append("<div style='width:80%;position: absolute;z-index: 3;color: #fff;top: 10px;left:10%;'>" +
						"<div class='toolTalkMenu'>" +
								"<span id='richList-all' class='toolTalkDiv-talk on'>财富排行</span>" +
								"<span id='richList-game'  class='toolTalkDiv-face'>比赛排行</span></div>"+
				"</div>");
				
				
				
			}
			
			
		},
		
		/*
		 * 创建财富的HTML数据*/
		_createRichData:function(json){
			var _t= this;
			var html ="<table width='100%' border='0' cellpadding='0' cellspacing='0'><thead><tr><th>排名</th><th>昵称</th><th>等级</th><th>乐豆</th></thead><tbody>";
			for(var i=0;i<json.l.length;i++){
				html +="<tr><td>"+(i+1)+"</td><td>"+json.l[i].n+"</td><td>"+_t._getGrade(json.l[i].b)+"</td><td>"+json.l[i].b+"</td></tr>";
				}
			
			html +="</tbody></table>";
			return html;
		},
		
		/*
		 * 创建详细个人比赛的HTML数据*/
		_createDetailGameData:function(json){
			var _t= this;
			var html ="<table width='100%' style='background:#b3dde8' border='0' cellpadding='0' cellspacing='0'><thead><tr style='background:#93c8d5;font-size:12px;'><th>排名</th><th>昵称</th><th>积分</th></thead><tbody>";
			for(var i=0;i<json.l.length;i++){
				html +="<tr><td>"+json.l[i].rank+"</td><td>"+json.l[i].nickName+"</td><td>"+json.l[i].score+"</td></tr>";
				}
			
			html +="</tbody></table>";
			return html;
		},
		
		_addGameData:function(){
			var url = getServiceURL() + "/popup/raceTopList?userId="+getMyUserId();
			//var url = getServiceURL() + "/popup/raceTopList?userId=1280";
			var _t = this;
			Game.ajax({
				  url: url,
				  dataType:"json",
				  success: function(data){
					 	_t._showBox.html(_t._createGameData(data)); 	
				  }
				});
			/*
			var data = {"l":[{"rank":1,"userId":1000,"roomId":111,"roomname":"xxx","score":8000},
			  	               {"rank":1,"userId":1000,"roomId":111,"roomname":"xxx","score":8000},
			  	             {"rank":1,"userId":1000,"roomId":111,"roomname":"xxx","score":8000}]};
			  	             */
			  	
			  	
		},
		
		/*
		 * 详细排行信息*/
		_addGameDetailData:function(roomId,table){
			var url = getServiceURL() + "/popup/raceTopDetails?userId="+getMyUserId()+"&roomId="+roomId;
			//var url = getServiceURL() + "/popup/raceTopDetails?userId=1280&roomId="+roomId;
			var _t = this;
			Game.ajax({
				  url: url,
				  dataType:"json",
				  success: function(data){
					 table.show().html(_t._createDetailGameData(data));	
				}
				});
			
			  	
		},
		
		/*
		 * 生成比赛排行的数据*/
		_createGameData:function(json){
			var html = [];
			html.push("<h2>你参加过的比赛如下：(整点结束后显示)</h2>");
			html.push("<ul class='gameLists'>");
			console.log(json.l.length)
			//如果没有结果
			if(json.l.length === 0){
				html.push("<li>今天你还没参加任何比赛场次或参加比赛还未结束</li>");
			}else{
				for(var i=0; i<json.l.length; i++){
					html.push("<li>" +
					          "<span>"+json.l[i].roomName+"</span>"+
					          "<span>排第"+json.l[i].rank+"名</span>"+
					          "<span><a class='gameLists-detail' data-roomId='"+json.l[i].roomId+"'>详情》</a></span>"+
							"</li><div class='gameLists-box' style='display:none'></div>");
				}
			}
			
			html.push("</ul>");
			
			html = html.join("");
			
			return html;
			
			
		},
		
		_eventRichListData:function(json){
			var _t = this;
			$("#richList-all").live("click touchend",function(){
				console.log("财富排行");
				$(this).addClass("on");
				$("#richList-game").removeClass("on");
				_t._showBox.html(_t._createRichData(json));
			});
			
			$("#richList-game").live("click touchend",function(){
				console.log("比赛排行");
				$(this).addClass("on");
				$("#richList-all").removeClass("on");
				_t._addGameData();
			});
			
			$(".gameLists-detail").live("click touchend",function(){
				var roomId = $(this).attr("data-roomId");
				$(".gameLists-box").hide();
				
				_t._addGameDetailData(roomId,$(this).parents("li").next());
			})
			
		},
		
		
		/*得到比赛房间的排行信息*/
		_createGameRankInfo:function(json){
			var html = [];
			html.push("<div class='gameRankInfo'>");
			html.push("<span class='gameRankInfolists'>完成对局："+json.myMatchCount+"/"+json.maxMatchCount+"</span>");
			html.push("<span class='gameRankInfolists'>比赛积分："+json.myChipCount+"</span>");
			html.push("<span>比赛排名：第"+json.myRank+"名  (前"+json.signUpUserCount+"个人参赛)</span></div>");
			html.push("<table width='100%' border='0' cellpadding='0' cellspacing='0'><thead><tr><th>排名</th><th>昵称</th><th>积分</th><th>局数</th></thead><tbody>");
			
			for(var i=0; i<json.rankList.length; i++){
				html.push("<tr><td>"+json.rankList[i].rankLevel+"</td>");
				html.push("<td>"+json.rankList[i].nickName+"</td>");
				html.push("<td>"+json.rankList[i].chipCount+"</td>");
				html.push("<td>"+json.rankList[i].matchCount+"/"+json.maxMatchCount+"局</td></tr>");
				//html.push("<td>"+json.rankList[i].rankLevelChange+"</td></tr>");
				}
			html.push("</tbody></table>");
			return html.join("");
					
		},
		
		/*得到等级*/
		_getGrade:function(code){
			for(var i=0; i<playerGrade.length; i++){
				if(playerGrade[i][1]>code){
					return playerGrade[i-1][0];
					}
				
				if(code>(playerGrade[playerGrade.length-1][1])){
					return "火星人";
				}
				}
			}
	}


